﻿@model CmsAdminWorkflowActiveModel

@{
    Layout = "~/admin/Templates/TelerikAdministration.cshtml";    
}

<p><a class="b-back-link" href="/admin/cmsworkflow"><i class="b-icon"></i> Back to workflow</a></p>
           
@RenderSection("ItemDescriptionBlock", false)

@{Html.RenderPartial("ErrorPanel");}

<div class="primary-content">    
    @*@{Html.RenderPartial("AlertPanel");}*@
    @{Html.RenderAction("WorkflowPreview", string.Format("Cms{0}", Model.EntityType), new { id = Model.Id });}
    @RenderSection("PropertyBlock", false)
    <div class="hide">
    @RenderSection("ApproveForm", false)
    @RenderSection("RejectForm", false)
    </div>
</div>
<div class="secondary-content">
    @RenderSection("ButtonsBlock")    
    @RenderSection("InfoBlock", false)
</div>
@section scriptBlock
{
<script type="text/javascript">
    // <![CDATA[
    $(document).ready(function () {
        var workflowTransitionId;
        var $rejectWorkflow = $('.cms-js-workflow-button-reject');
        var $approveWorkflow = $('.cms-js-workflow-button-approve');
        $rejectWorkflow.each(function () {
            var $e = $(this);
            $e.fancybox({
                content: '#cms-js-reject',
                type: 'inline',
                autoScale: false,
                autoDimensions: true,
                onComplete: function () {
                    workflowTransitionId = $e.attr('id').replace('Workflow-', '');
                }
            });
        });
        
        $approveWorkflow.each(function () {
            var $e = $(this);
            $e.fancybox({
                content: '#cms-js-approve',
                type: 'inline',
                autoScale: false,
                autoDimensions: true,
                onComplete: function () {
                    workflowTransitionId = $e.attr('id').replace('Workflow-', '');
                }
            });
        });
                    
        $('.cms-js-workflow-cancel').click(function () {
            $.fancybox.close();
        });
        $('.cms-js-workflow-action').click(function () {
            var inputId = $(this).attr('id');
            var $form = inputId == 'cms-js-workflow-submit' ? $('#cms-js-approve-form') : $('#cms-js-reject-form');
            var requestUrl = $form.attr('action');
            if (requestUrl === '') {
                requestUrl = window.location.href;
            }
            $.post(requestUrl, $form.formSerialize() + '&workflowTransitionId=' + workflowTransitionId)
                    .success(function (data) {
                        if (data == 1) {
                            window.location.href = window.location.href;
                        }
                        else {
                            $.fancybox.close();
                        }
                    })
                    .error(function () {
                        $.fancybox.close();
                    });
        });
    });
    // ]]>
</script>
@RenderSection("scriptBlock", false)
}  
